package com.chris.cc.user.mapper;

import com.chris.cc.user.model.entity.Permission;
import com.chris.cc.user.model.entity.RolePermission;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

/**
 * Copyright (c) 2018-2025, chris All rights reserved.
 * <p>
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 * <p>
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the pig4cloud.com developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * <p>
 * Author: haoka (haokang207@126.com)
 * <p>
 * Date: 2018/8/23 16:05
 **/
@Repository
public interface RolePermissionMapper extends Mapper<RolePermission> {
    @Select("select p.* from u_user_role u " +
            "left join u_role_permission r on r.role_id=u.role_id " +
            "left join u_permission p on p.permission_id=r.permission_id " +
            "where u.user_id=${userId} and p.permission_id is not null")
    List<Permission> selectPermissionByUserId(@Param("userId") Long userId);

    @Select("select p.* from u_role_permission r " +
            "left join u_permission p on p.permission_id=r.permission_id " +
            "where r.role_id=${roleId} and p.permission_id is not null")
    List<Permission> selectPermissionByRoleId(@Param("roleId") Long roleId);
}
